package com.aegean.CommercialHotelBookSystem.shop.action;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.aegean.CommercialHotelBookSystem.model.Room;

/**
 * Servlet implementation class ShopHotel_ClickRooms
 */
public class ShopHotel_ClickRooms extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ShopHotel_ClickRooms() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		HttpSession session = request.getSession();
		List<Room> requestRooms = new ArrayList<Room>();
		List<Room> rooms = (List<Room>) session
				.getAttribute("Hotel_ClickRooms");
		int page = Integer.parseInt(request.getParameter("page"));
		int pagesize =8;
		for (int i = (page - 1) * pagesize; i < (page - 1) * pagesize
				+ pagesize; i++) {
			System.out.println(rooms.get(i).getRoom_Name());
			requestRooms.add(rooms.get(i));
			if (i == rooms.size() - 1) {
				break;
			}
		}
		request.setAttribute("Hotel_ClickRooms", requestRooms);
		request.getRequestDispatcher("Hotel_ClickhotelRooms.jsp").forward(
				request, response);
	}

}
